#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
int fd;
static void sigio_signal_func(int signum)
{
    printf("timestamp: %d\n",read(fd, NULL, 0));	
}

int main(int argc, char *argv[])
{
	int ret;
	fd = open("/dev/Timestamp_Driver", O_RDWR);
	if (fd < 0) {
		printf("Can't open file \r\n");
		return -1;
	}   
    signal(SIGIO, sigio_signal_func);

    fcntl(fd, F_SETOWN, getpid());			// 将当前进程的进程号告诉给内核
    //flags = fcntl(fd, F_GETFD);				// 获取当前的进程状态
    fcntl(fd, F_SETFL, fcntl(fd, F_GETFD) | FASYNC);		// 设置进程启用异步通知功能

    printf("0.5s test \n");
    ioctl(fd, 1, 500);	
    printf("timestamp: %d\n",read(fd, NULL, 0));	
    printf("0.5s test \n");
    ioctl(fd, 1, 500);	
    printf("timestamp: %d\n",read(fd, NULL, 0));	
    printf("2s test \n");
    ioctl(fd, 0, 2);	
    printf("timestamp: %d\n",read(fd, NULL, 0));	
    printf("2s test \n");
    ioctl(fd, 0, 2);
    printf("timestamp: %d\n",read(fd, NULL, 0));	
    printf("test done\n");

    printf("Block Delay Done\n");

    printf("timestamp: %d\n",read(fd, NULL, 0));	
    printf("0.5s test \n");
    ioctl(fd, 0x11, 500);
    printf("0.5s test \n");
    ioctl(fd, 0x11, 500);
    printf("2s test \n");
    ioctl(fd, 0x10, 2);
    printf("2s test \n");
    ioctl(fd, 0x10, 2);
    printf("2s test \n");

	close(fd);
}